package com.ryenlii.datatrans.controller;

import cn.hutool.core.util.StrUtil;
import com.ryenlii.datatrans.core.constant.TopicConst;
import com.ryenlii.datatrans.entity.KafkaMessage;
import com.ryenlii.datatrans.service.IProducerService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import jakarta.annotation.Resource;

@RestController
@RequestMapping("/kafka")
public class KafkaTestController {
    @Resource
    private IProducerService producerService;

    @PostMapping("/send")
    public void send(@RequestBody KafkaMessage message) {

        String mess = message.getMessage();

        if (StrUtil.isNotBlank(mess) && (StrUtil.isNotBlank(message.getTopic()))) {
            producerService.sendMessage(message.getTopic(), mess);
        } else {
            producerService.sendMessage(TopicConst.PLATFORM_SEND_CITY_DATA, mess);
        }
    }

}

